using Microsoft.AspNetCore.Mvc;
using SqlKata;
using SqlKata.Execution;
using SqlKataDemo.WebApi.Models;
using SqlKataDemo.WebApi.Services;

namespace SqlKataDemo.WebApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class OrderController : ControllerBase
    {
        private readonly IDbFactory _dbFactory;

        public OrderController(IDbFactory dbFactory)
        {
            _dbFactory = dbFactory;
        }

        [HttpGet]
        public Order Get()
        {
            var query = new Query("order");
            var order = _dbFactory.GetFactory().Get<Order>(query).FirstOrDefault();
            return order;
        }
    }
}